import { resolve } from 'path'
import type { PluginOption } from 'vite'
import Vue from '@vitejs/plugin-vue'
import VueJsx from '@vitejs/plugin-vue-jsx'
import Progress from 'vite-plugin-progress'
import UnoCSS from 'unocss/vite'
import createStyleImport from './styleImport'
import createSvgIcon from './icon'
import createEslintPlugin from './eslint'
import createHtmlEntry from './html'
import PurgeIcons from 'vite-plugin-purge-icons'
import createMockServe from './mock'
import createVueI18nPlugin from './I18n'
import createLayouts from './layouts'
import createPages from './pages'
const root = process.cwd()

function pathResolve(dir: string) {
  return resolve(root, '.', dir)
}
export default function createVitePlugins(viteEnv, isBuild = false) {
  const { VITE_USE_ALL_ELEMENT_PLUS_STYLE, VITE_APP_TITLE, VITE_USE_MOCK } = viteEnv
  const vitePlugins: (PluginOption | PluginOption[])[] = [
    Vue({
      script: { defineModel: true }
    }),
    VueJsx(),
    Progress()
  ]
  if (VITE_USE_ALL_ELEMENT_PLUS_STYLE === 'false') vitePlugins.push(createStyleImport())
  if (VITE_USE_MOCK === 'true') vitePlugins.push(createMockServe(isBuild))
  vitePlugins.push(createEslintPlugin())
  vitePlugins.push(createHtmlEntry(VITE_APP_TITLE))
  vitePlugins.push(createSvgIcon(pathResolve('src/assets/svgs')))
  vitePlugins.push(PurgeIcons())
  vitePlugins.push(UnoCSS())
  vitePlugins.push(createVueI18nPlugin([pathResolve('src/locales/**')]))

  // vitePlugins.push(createLayouts())
  // vitePlugins.push(createPages())
  // vitePlugins.push(createInspector())
  // vitePlugins.push(createMock(viteEnv, isBuild))
  // vitePlugins.push(...createCompression(viteEnv, isBuild))
  // vitePlugins.push(createArchiver(viteEnv))
  // vitePlugins.push(createConsole())
  // vitePlugins.push(createBanner())
  return vitePlugins
}
